package hk.m4s.lr.repair.test.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.MyWaiteOrderModel;
import hk.m4s.lr.repair.test.ui.goods.GoodsEventActivity;
import hk.m4s.lr.repair.test.ui.user.UnprocessedMoneyActivity;
import hk.m4s.lr.repair.test.views.listview.InnerListView;


/**
 * @author
 */
public class ItemUnprocessedAdapter extends BaseAdapter {
    private UnprocessedMoneyActivity context;
    public List<MyWaiteOrderModel> items;
    int selectNums=0;
    public ItemUnprocessedAdapter(UnprocessedMoneyActivity context,
                                  List<MyWaiteOrderModel> items) {
        this.context = context;
        this.items = items;
    }

    public int getCount() {
        return 2;
    }

    public Object getItem(int position) {
        return getView(position, null, null);
    }

    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.item_my_waite_money, null);
            holder = new ViewHolder();
            holder.order_shop_state = (TextView) convertView.findViewById(R.id.order_shop_state);
            holder.order_shop_name = (TextView) convertView.findViewById(R.id.order_shop_name);
            holder.order_shop_price = (TextView) convertView.findViewById(R.id.order_shop_price);
            holder.order_shop_size = (TextView) convertView.findViewById(R.id.order_shop_size);
            holder.order_shop_num = (TextView) convertView.findViewById(R.id.order_shop_num);
            holder.order_shop_fan = (TextView) convertView.findViewById(R.id.order_shop_fan);
            holder.order_shop_img = (ImageView) convertView.findViewById(R.id.order_shop_img);
            holder.goEvent= (LinearLayout) convertView.findViewById(R.id.goEvent);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.goEvent.setTag(position);
//        MyWaiteOrderModel model = items.get(position);
//        holder.order_shop_name.setText(model.getName());
//        holder.order_shop_price.setText(MoneyTool.getLocalMoney(model.getPrice()));
//        holder.order_shop_size.setText(model.getSize());
//        holder.order_shop_num.setText("x" + model.getBuyNum());
//        try {
//            Glide.with(context).load(model.getImg()).asBitmap().placeholder(R.mipmap.upload_photo).error(R.mipmap.upload_photo).into(holder.order_shop_img);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

        holder.goEvent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = (Integer) v.getTag();
                MyWaiteOrderModel model = items.get(num);
                Intent aboutIntent = new Intent(context, GoodsEventActivity.class);
                //aboutIntent.putExtra("goods_id",model.getGoods_id());
                context.startActivity(aboutIntent);
            }
        });

        return convertView;
    }

    private class ViewHolder {
        TextView order_shop_time;
        TextView order_shop_state;
        TextView order_shop_name;
        TextView order_shop_price;
        TextView order_shop_size;
        TextView order_shop_num;
        TextView order_shop_fan;
        TextView order_shop_buynum;
        TextView order_shop_totlaprice;
        ImageView order_shop_img;
        Button cancle_order, pay_btn;
        private RelativeLayout header;
        LinearLayout goEvent;
        InnerListView itemList;
    }
}
